from afast_core.core_tools.encrypt_helper import md5
from afast_core.core_tools.snow_flake_helper import Snow
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.services.service_businesses import \
    Businesses



class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    appid: str = Body(..., title="appid", )
    name: str = Body(...,  title="name", )
    credentials: str = Body('',  title="credentials", )
    dc_number: str = Body(default=None,  title="dc_number", )
    department: str = Body('',  title="department", )
    des : str = Body('',  title="des", )
    excel : str = Body('',  title="excel", )
    fee  : str = Body('',  title="fee", )
    icon :str = Body('',  title="icon", )
    is_rest: int = Body('', title="is_rest", )
    openid: str = Body('', title="openid", )
    status : int = Body(0,  title="status", )
    posts :str = Body('',  title="icon", )
    station_name :str = Body(default=None,  title="icon", )
    tel :str = Body('',  title="icon", )
    worktab :str = Body('',  title="icon", )
    is_more_station : int = Body(0,  title="is_more_station", )
    is_admin  : int = Body(0,  title="is_admin", )
    is_notice_to_doctor: int = Body(0, title="is_notice_to_doctor", )
    # 退款操作秘密
    refundpassword :str = Body(default=None,  title="icon", )




class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class InfirmaryBusinessesDoctorUserAddController(IController):

    def business_login(self):
        pass
        #
        self.schema_param.icon ='/infirmary/api/images/moren.png' if not self.schema_param.icon else self.schema_param.icon
        self.schema_param.dc_number = f"{self.schema_param.appid}{Snow('', 5).get(is_random=False)}"
        # 退款秘密的加密录入
        self.schema_param.refundpassword = md5(
            self.schema_param.refundpassword) if self.schema_param.refundpassword else None

        result = Businesses.add_businesses_doctor_user_info(**self.schema_param.dict())
        # result = None
        if result:
            self.response_msg = '添加成功'
        else:
            self.response_ok = False
            self.response_msg = '添加失败'
            return None

